<%-- 
    Document   : myAccount
    Created on : 29 May, 2012, 8:46:01 PM
    Author     : bharat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %> 
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="frame1css.css">
        <link rel="stylesheet" type="text/css" href="frame2css.css">
        <title>My Account</title>
    </head>
    <body>

        <%

            Connection con = null;
            PreparedStatement pstmt1 = null;
            ResultSet rs = null;
            Connection con2 = null;
            PreparedStatement pstmt2 = null;
            ResultSet rs2 = null;

            String username = (String) session.getAttribute("username");
            String id = (String) session.getAttribute("id");
            if (username != null) {

                try {
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");
                    con2 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");

                    pstmt1 = con.prepareStatement("select *from registered_users_db where usr_name=?");
                    pstmt1.setString(1, username);
                    rs = pstmt1.executeQuery();

                    pstmt2 = con2.prepareStatement("select *from posts where postedby=?");
                    pstmt2.setString(1, username);
                    rs2 = pstmt2.executeQuery();

        %>
        <div class="container">
            <table class="" border="2" width="40%" bgcolor="#ff55ff">
                <%if (rs.next()) {%>
                <tr>
                    <td>
                        ID
                    </td>
                    <td>
                        <%=rs.getString(1)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        First Name
                    </td>
                    <td>
                        <%=rs.getString(2)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Last Name
                    </td>
                    <td>
                        <%=rs.getString(3)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Email
                    </td>
                    <td>
                        <%=rs.getString(4)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Course
                    </td>
                    <td>
                        <%=rs.getString(7)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Course Year
                    </td>
                    <td>
                        <%=rs.getString(8)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        User Name
                    </td>
                    <td>
                        <%=rs.getString(2)%>
                        <a href="logout.jsp">Logout</a>
                    </td>
                </tr>
                <tr>
                    <td>

                    </td>
                    <td>

                        <a href="post.jsp" target="frame2">Create a post</a>
                    </td>
                </tr>
            </table>

            <% }%>
        </div>
        <%
                } catch (Exception e) {
                    response.sendError(555, e.getMessage());
                } finally {

                    if (con != null) {
                        try {
                            con.close();
                        } catch (Exception e) {
                        }
                    }
                    if (pstmt1 != null) {
                        try {
                            pstmt1.close();
                        } catch (Exception e) {
                        }
                    }
                    if (rs != null) {
                        try {
                            rs.close();
                        } catch (Exception e) {
                        }
                    }
                }
            } else {
                response.sendRedirect("two.jsp");
            }
        %>
        
    </body>
</html>
